package com.sss.hloster0503;

import java.util.*;

public class TestZuChe02 {

	public static void main(String[] args) {
		test02();
	}

	private static void test02() {
		int index = -1; // 用于显示序列号
		Scanner input = new Scanner(System.in);
		// 创建ArrayList集合，用于存放测量
		List vehAL = new ArrayList();
		Vehicle c1 = new Car("战神", "长城");
		Vehicle c2 = new Car("跑得快", "红旗");
		Vehicle t1 = new Truck("大理石", "5吨");
		Vehicle t2 = new Truck("大理石二代", "10吨");
		vehAL.add(c1);
		vehAL.add(c2);
		vehAL.add(t1);
		vehAL.add(t2);
		System.out.println("***显示“租车系统”中全部车辆***");
		index = 1;
		// 增强for循环遍历
		for (Object obj : vehAL) {
			if (obj instanceof Car) {
				Car car = (Car) obj;
				System.out.println(index + "该车是轿车，其车名为：" + car.getName());

			} else {
				Truck truck = (Truck) obj;
				System.out.println(index + "该车是轿车，其车名为：" + truck.getName());

			}
			index++;
		}
		System.out.println("请输入要显示详细信息的车辆编号：");
		// 根据索引获取vehAL集合中元素，类型转换后调用show()方法输出
		((Vehicle) vehAL.get(input.nextInt() - 1)).show();
	}
}
